# 选择排序

#     vsmallestIdx
# [2, 3, 5, 9, 6, 8]
#        ^i
#     ^currentIdx
#
# smallestIdx = 3
# 
def selectionSort(array):
  currentIdx = 0

  while currentIdx < len(array) - 1:
    smallestIdx = currentIdx

    for i in range(currentIdx + 1, len(array)):
      if array[smallestIdx] > array[i]:
        smallestIdx = i
    
    array[currentIdx], array[smallestIdx] = array[smallestIdx], array[currentIdx]
    currentIdx += 1

  return array

print(selectionSort([8, 5, 2, 9, 6, 3]))
